package com.infore.airsupervise.ui.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.TextView;

import com.infore.airsupervise.R;

/**
 * 自定义Badge View
 *
 * @features: 用于显示推送消息条数
 * @author: Ding Xinlin
 * @date: 2017/02/27 17:13
 */

public class CustomBadgeView extends TextView {

    private int badgeValue;

    public CustomBadgeView(Context context) {
        this(context, null);
    }

    public CustomBadgeView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomBadgeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        // 背景、字体颜色和大小
        this.setBackgroundResource(R.drawable.bg_badge_view);
        this.setTextColor(Color.WHITE);
        this.setTextSize(14f);

        // 默认隐藏
        this.setVisibility(GONE);
    }

    /**
     * 获取徽章值
     * @return
     */
    public int getBadgeValue() {
        return badgeValue;
    }

    /**
     * 设置徽章值
     * @param badgeValue
     */
    public void setBadgeValue(int badgeValue) {
        this.badgeValue = badgeValue;
        if (badgeValue <= 0) {
            this.setVisibility(GONE);
        } else {
            this.setVisibility(VISIBLE);
            this.setText("" + badgeValue);
        }
    }

}
